function formatNumber(n) {
	const str = n.toString()
	return str[1] ? str : `0${str}`
}

export function formatTime(date) {
	const year = date.getFullYear()
	const month = date.getMonth() + 1
	const day = date.getDate()

	const hour = date.getHours()
	const minute = date.getMinutes()
	const second = date.getSeconds()

	const t1 = [year, month, day].map(formatNumber).join('/')
	const t2 = [hour, minute, second].map(formatNumber).join(':')

	return `${t1} ${t2}`
}


export function timestampToTime(timestamp) {
	var date = new Date(parseInt(timestamp)); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
	var Y = date.getFullYear() + '-';
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
	var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
	var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
	var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
	return Y + M + D + h + m + s;
}
export function formatDate(date) {
	var arr = date.split('-')
	return arr[1] + '-' + arr[2];
}

export function getUrlVal() {
	var url = window.location.href
	var Request = new Object();
	if (url.indexOf("?") != -1) {　
		var urlindex = url.indexOf("?")+1　
		var str = url.substr(urlindex)
			　　 var strs = str.split("&");　　
		for (var i = 0; i < strs.length; i++){　　
			var tarGets = strs[i].split("=")
			Request[tarGets[0]] = unescape(tarGets[1]);　　
		}
		return Request
	} else {
		return Request
	}
}



export default {
	formatNumber,
	formatTime,
	formatDate,
	timestampToTime
}
//时间戳转换为 5月21日 这种格式    date:时间戳数字
